{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.5.2\n"
     ]
    }
   ],
   "source": [
    "import paddle\n",
    "import paddle.nn.functional as F\n",
    "from paddle.nn import Linear\n",
    "import numpy as np\n",
    "import os\n",
    "import json\n",
    "import random\n",
    "print(paddle.__version__)\n",
    "from paddle.nn import Conv2D,MaxPool2D"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_data(mode='train'):\n",
    "    with open('new_mnist.json')as f:\n",
    "        data=json.load(f)\n",
    "    train_set,val_set,eval_set=data\n",
    "    if mode=='train':\n",
    "        imgs,labels=train_set[0],train_set[1]\n",
    "    elif mode=='valid':\n",
    "        imgs,labels=val_set[0],val_set[1]\n",
    "    elif mode=='eval':\n",
    "        imgs,labels=eval_set[0],eval_set[1]\n",
    "    else:\n",
    "        raise Exception(\"mode can only be one of['train','valid','eval']\")\n",
    "    print(\"训练数据集数量:\",len(imgs))\n",
    "    imgs_length=len(imgs)\n",
    "    index_list=list(range(imgs_length))\n",
    "    BATCHSIZE=100\n",
    "    def data_generator():\n",
    "        if mode=='train':\n",
    "            random.shuffle(index_list)\n",
    "        imgs_list=[]\n",
    "        labels_list=[]\n",
    "        for i in index_list:\n",
    "            img=np.array(imgs[i]).astype('float32')\n",
    "            label=np.reshape(labels[i],[1]).astype('int64')\n",
    "            imgs_list.append(img)\n",
    "            labels_list.append(label)\n",
    "            if len(img_list)==BATCHSIZE:\n",
    "                yield np.array(imgs_list),np.array(label_list)\n",
    "                imgs_list=[]\n",
    "                labels_list=[]\n",
    "        if len(imgs_list)>0:\n",
    "            yield np.array(imgs_list),np.array(labels_list)\n",
    "    return data_generator\n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_data(mode='train'):\n",
    "    with open('new_mnist.json')as f:\n",
    "        data=json.load(f)\n",
    "    train_set,val_set,eval_set=data\n",
    "    if mode=='train':\n",
    "        imgs,labels=train_set[0],train_set[1]\n",
    "    elif mode=='valid':\n",
    "        imgs,labels=val_set[0],val_set[1]\n",
    "    elif mode=='eval':\n",
    "        imgs,labels=eval_set[0],eval_set[1]\n",
    "    else:\n",
    "        raise Exception(\"mode can only be one of['train','valid','eval']\")\n",
    "    print(\"训练数据集数量:\",len(imgs))\n",
    "    imgs_length=len(imgs)\n",
    "    index_list=list(range(imgs_length))\n",
    "    BATCHSIZE=100\n",
    "    def data_generator():\n",
    "        if mode=='train':\n",
    "            random.shuffle(index_list)\n",
    "        imgs_list=[]\n",
    "        labels_list=[]\n",
    "        for i in index_list:\n",
    "            img=np.reshape(imgs[i],[1,28,28]).astype('float32')\n",
    "            label=np.reshape(labels[i],[1]).astype('int64')\n",
    "            imgs_list.append(img)\n",
    "            labels_list.append(label)\n",
    "            if len(imgs_list)==BATCHSIZE:\n",
    "                yield np.array(imgs_list),np.array(labels_list)\n",
    "                imgs_list=[]\n",
    "                labels_list=[]\n",
    "        if len(imgs_list)>0:\n",
    "            yield np.array(imgs_list),np.array(labels_list)\n",
    "    return data_generator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "class LeNetModel(paddle.nn.Layer):\n",
    "    def __init__(self):\n",
    "        super(LeNetModel,self).__init__()\n",
    "        self.conv1=paddle.nn.Conv2D(in_channels=1,out_channels=6,kernel_size=5,stride=1)\n",
    "        self.pool1=paddle.nn.MaxPool2D(kernel_size=2,stride=2)\n",
    "        self.conv2=paddle.nn.Conv2D(in_channels=6,out_channels=16,kernel_size=5,stride=1)\n",
    "        self.pool2=paddle.nn.MaxPool2D(kernel_size=2,stride=2) \n",
    "        self.fc1=paddle.nn.Linear(256,120)\n",
    "        self.fc2=paddle.nn.Linear(120,84)\n",
    "        self.fc3=paddle.nn.Linear(84,10)\n",
    "    def forward(self,x):\n",
    "        x=self.conv1(x)\n",
    "        x=F.relu(x)\n",
    "        x=self.pool1(x)\n",
    "        x=self.conv2(x)\n",
    "        x=F.relu(x)\n",
    "        x=self.pool2(x)\n",
    "        x=paddle.flatten(x,start_axis=1,stop_axis=-1)\n",
    "        x=self.fc1(x)\n",
    "        x=F.relu(x)\n",
    "        x=self.fc2(x)\n",
    "        x=F.relu(x)\n",
    "        x=self.fc3(x)\n",
    "        return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "def train(model):\n",
    "    model.train()\n",
    "    opt=paddle.optimizer.SGD(learning_rate=0.01,parameters=model.parameters())\n",
    "    EPOCH_NUM=5\n",
    "    for epoch_id in range(EPOCH_NUM):\n",
    "        for batch_id,data in enumerate(train_loader()):\n",
    "            images,labels=data\n",
    "            images=paddle.to_tensor(images)\n",
    "            labels=paddle.to_tensor(labels)\n",
    "            predicts=model(images)\n",
    "            loss=F.softmax_with_cross_entropy(predicts,labels)\n",
    "            avg_loss=paddle.mean(loss)\n",
    "            if batch_id %200 ==0:\n",
    "                print(\"epoch:{},batch:{},loss is:{}\".format(epoch_id,batch_id,avg_loss.numpy()))\n",
    "            avg_loss.backward()\n",
    "            opt.step()\n",
    "            opt.clear_grad()\n",
    "        model.eval()\n",
    "        accuracies=[]\n",
    "        losses=[]\n",
    "        for batch_id,data in enumerate(valid_loader()):\n",
    "            images,labels=data\n",
    "            images=paddle.to_tensor(images)\n",
    "            labels=paddle.to_tensor(labels)\n",
    "            logits=model(images)\n",
    "            pred=F.softmax(logits)\n",
    "            loss=F.softmax_with_cross_entropy(logits,labels)\n",
    "            acc=paddle.metric.accuracy(pred,labels)\n",
    "            accuracies.append(acc.numpy())\n",
    "            losses.append(loss.numpy())\n",
    "            print(\"[validation]accuracy/loss:{}/{}\".format(np.mean(accuracies),np.mean(losses)))\n",
    "            model.train()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练数据集数量: 50000\n",
      "训练数据集数量: 10000\n",
      "epoch:0,batch:0,loss is:[2.8483682]\n",
      "epoch:0,batch:200,loss is:[0.46451187]\n",
      "epoch:0,batch:400,loss is:[0.2585327]\n",
      "[validation]accuracy/loss:0.9399999976158142/0.22455529868602753\n",
      "[validation]accuracy/loss:0.949999988079071/0.1806151419878006\n",
      "[validation]accuracy/loss:0.9399999976158142/0.24010208249092102\n",
      "[validation]accuracy/loss:0.9249999523162842/0.26718807220458984\n",
      "[validation]accuracy/loss:0.9219999313354492/0.2920357882976532\n",
      "[validation]accuracy/loss:0.9183332920074463/0.3012526333332062\n",
      "[validation]accuracy/loss:0.9214285612106323/0.29954347014427185\n",
      "[validation]accuracy/loss:0.92249995470047/0.2945657968521118\n",
      "[validation]accuracy/loss:0.9244444370269775/0.28047308325767517\n",
      "[validation]accuracy/loss:0.9290000200271606/0.26753565669059753\n",
      "[validation]accuracy/loss:0.9299999475479126/0.2591667175292969\n",
      "[validation]accuracy/loss:0.9308332800865173/0.2550649642944336\n",
      "[validation]accuracy/loss:0.9284614324569702/0.2615581154823303\n",
      "[validation]accuracy/loss:0.9278570413589478/0.25726455450057983\n",
      "[validation]accuracy/loss:0.9299999475479126/0.2513546049594879\n",
      "[validation]accuracy/loss:0.9312499761581421/0.24409253895282745\n",
      "[validation]accuracy/loss:0.9317646622657776/0.24173685908317566\n",
      "[validation]accuracy/loss:0.9322221279144287/0.24361026287078857\n",
      "[validation]accuracy/loss:0.9336841106414795/0.23879380524158478\n",
      "[validation]accuracy/loss:0.9319998621940613/0.2407776415348053\n",
      "[validation]accuracy/loss:0.929999828338623/0.2493550032377243\n",
      "[validation]accuracy/loss:0.9254543781280518/0.2605227530002594\n",
      "[validation]accuracy/loss:0.9252172708511353/0.26303985714912415\n",
      "[validation]accuracy/loss:0.9258332848548889/0.2604565918445587\n",
      "[validation]accuracy/loss:0.9275999665260315/0.2560957968235016\n",
      "[validation]accuracy/loss:0.9292306900024414/0.2502753734588623\n",
      "[validation]accuracy/loss:0.9296295642852783/0.24807807803153992\n",
      "[validation]accuracy/loss:0.9292856454849243/0.24794986844062805\n",
      "[validation]accuracy/loss:0.9272413849830627/0.2537005841732025\n",
      "[validation]accuracy/loss:0.9233332872390747/0.2646789848804474\n",
      "[validation]accuracy/loss:0.9232257604598999/0.2630969285964966\n",
      "[validation]accuracy/loss:0.9237499833106995/0.26155394315719604\n",
      "[validation]accuracy/loss:0.9242424368858337/0.2607515752315521\n",
      "[validation]accuracy/loss:0.9252941012382507/0.25661322474479675\n",
      "[validation]accuracy/loss:0.9262856841087341/0.2533459961414337\n",
      "[validation]accuracy/loss:0.9249999523162842/0.25536781549453735\n",
      "[validation]accuracy/loss:0.9248647689819336/0.2550787329673767\n",
      "[validation]accuracy/loss:0.9252630472183228/0.25291019678115845\n",
      "[validation]accuracy/loss:0.9248716831207275/0.2523537576198578\n",
      "[validation]accuracy/loss:0.9237500429153442/0.2551107108592987\n",
      "[validation]accuracy/loss:0.9229268431663513/0.25635796785354614\n",
      "[validation]accuracy/loss:0.9233332872390747/0.25536975264549255\n",
      "[validation]accuracy/loss:0.9239534735679626/0.25282618403434753\n",
      "[validation]accuracy/loss:0.9243181347846985/0.252046674489975\n",
      "[validation]accuracy/loss:0.9242221117019653/0.25039586424827576\n",
      "[validation]accuracy/loss:0.9234781861305237/0.2507861852645874\n",
      "[validation]accuracy/loss:0.9240424633026123/0.24882370233535767\n",
      "[validation]accuracy/loss:0.9247916340827942/0.2471952587366104\n",
      "[validation]accuracy/loss:0.9246938228607178/0.24672582745552063\n",
      "[validation]accuracy/loss:0.9241999983787537/0.24785776436328888\n",
      "[validation]accuracy/loss:0.9243137240409851/0.24715545773506165\n",
      "[validation]accuracy/loss:0.924423098564148/0.24509747326374054\n",
      "[validation]accuracy/loss:0.9249056577682495/0.24330304563045502\n",
      "[validation]accuracy/loss:0.9253703951835632/0.24250847101211548\n",
      "[validation]accuracy/loss:0.9254545569419861/0.24170982837677002\n",
      "[validation]accuracy/loss:0.9257141947746277/0.24108287692070007\n",
      "[validation]accuracy/loss:0.9263157248497009/0.2393021583557129\n",
      "[validation]accuracy/loss:0.9263792634010315/0.23939824104309082\n",
      "[validation]accuracy/loss:0.9266100525856018/0.2386133223772049\n",
      "[validation]accuracy/loss:0.9269999265670776/0.2364601194858551\n",
      "[validation]accuracy/loss:0.9273769855499268/0.23462647199630737\n",
      "[validation]accuracy/loss:0.9280644655227661/0.23287716507911682\n",
      "[validation]accuracy/loss:0.9276190400123596/0.23361393809318542\n",
      "[validation]accuracy/loss:0.9278124570846558/0.2328181117773056\n",
      "[validation]accuracy/loss:0.9275383949279785/0.23378649353981018\n",
      "[validation]accuracy/loss:0.928030252456665/0.23252645134925842\n",
      "[validation]accuracy/loss:0.9277611374855042/0.23279635608196259\n",
      "[validation]accuracy/loss:0.9282352328300476/0.23138883709907532\n",
      "[validation]accuracy/loss:0.9289854764938354/0.22994297742843628\n",
      "[validation]accuracy/loss:0.9295714497566223/0.22839972376823425\n",
      "[validation]accuracy/loss:0.9298591017723083/0.2288816273212433\n",
      "[validation]accuracy/loss:0.9298610687255859/0.22808335721492767\n",
      "[validation]accuracy/loss:0.9300000071525574/0.2274731993675232\n",
      "[validation]accuracy/loss:0.9298648238182068/0.22842071950435638\n",
      "[validation]accuracy/loss:0.9297332763671875/0.22823353111743927\n",
      "[validation]accuracy/loss:0.9293420910835266/0.2294527143239975\n",
      "[validation]accuracy/loss:0.9292207360267639/0.2302151322364807\n",
      "[validation]accuracy/loss:0.9291024804115295/0.23149454593658447\n",
      "[validation]accuracy/loss:0.9296202063560486/0.23035110533237457\n",
      "[validation]accuracy/loss:0.9297499656677246/0.2296692430973053\n",
      "[validation]accuracy/loss:0.9293826818466187/0.2295968234539032\n",
      "[validation]accuracy/loss:0.9300000071525574/0.22779671847820282\n",
      "[validation]accuracy/loss:0.9307228922843933/0.22596284747123718\n",
      "[validation]accuracy/loss:0.9311904907226562/0.22466622292995453\n",
      "[validation]accuracy/loss:0.9310588240623474/0.2240658849477768\n",
      "[validation]accuracy/loss:0.9316279292106628/0.22235237061977386\n",
      "[validation]accuracy/loss:0.9320690035820007/0.2217833548784256\n",
      "[validation]accuracy/loss:0.9322726726531982/0.22064897418022156\n",
      "[validation]accuracy/loss:0.9324718117713928/0.22041568160057068\n",
      "[validation]accuracy/loss:0.9332221150398254/0.2183687388896942\n",
      "[validation]accuracy/loss:0.9338459968566895/0.21663706004619598\n",
      "[validation]accuracy/loss:0.9342390298843384/0.21502941846847534\n",
      "[validation]accuracy/loss:0.9345160126686096/0.2144746482372284\n",
      "[validation]accuracy/loss:0.9340423941612244/0.2162318229675293\n",
      "[validation]accuracy/loss:0.9337893724441528/0.21619053184986115\n",
      "[validation]accuracy/loss:0.9344790577888489/0.2143467664718628\n",
      "[validation]accuracy/loss:0.9348452687263489/0.2135056108236313\n",
      "[validation]accuracy/loss:0.9342856407165527/0.21622882783412933\n",
      "[validation]accuracy/loss:0.9349493980407715/0.21449929475784302\n",
      "[validation]accuracy/loss:0.9343998432159424/0.21646817028522491\n",
      "epoch:1,batch:0,loss is:[0.1483083]\n",
      "epoch:1,batch:200,loss is:[0.15279558]\n",
      "epoch:1,batch:400,loss is:[0.08431108]\n",
      "[validation]accuracy/loss:0.9599999785423279/0.11912382394075394\n",
      "[validation]accuracy/loss:0.9599999785423279/0.11486296355724335\n",
      "[validation]accuracy/loss:0.9566666483879089/0.17146934568881989\n",
      "[validation]accuracy/loss:0.9399999380111694/0.20191825926303864\n",
      "[validation]accuracy/loss:0.9339998960494995/0.22034305334091187\n",
      "[validation]accuracy/loss:0.934999942779541/0.2274424284696579\n",
      "[validation]accuracy/loss:0.9371427893638611/0.22318856418132782\n",
      "[validation]accuracy/loss:0.9399999380111694/0.21526658535003662\n",
      "[validation]accuracy/loss:0.9433333277702332/0.2013629972934723\n",
      "[validation]accuracy/loss:0.9469999074935913/0.19070635735988617\n",
      "[validation]accuracy/loss:0.9481817483901978/0.18094557523727417\n",
      "[validation]accuracy/loss:0.9474999308586121/0.176951065659523\n",
      "[validation]accuracy/loss:0.9461537599563599/0.18623752892017365\n",
      "[validation]accuracy/loss:0.9464284777641296/0.185015469789505\n",
      "[validation]accuracy/loss:0.9479999542236328/0.1796814352273941\n",
      "[validation]accuracy/loss:0.9481250047683716/0.1733352243900299\n",
      "[validation]accuracy/loss:0.9488234519958496/0.16925013065338135\n",
      "[validation]accuracy/loss:0.948888897895813/0.17078392207622528\n",
      "[validation]accuracy/loss:0.949999988079071/0.16714420914649963\n",
      "[validation]accuracy/loss:0.9494999647140503/0.16953045129776\n",
      "[validation]accuracy/loss:0.9480952024459839/0.17454147338867188\n",
      "[validation]accuracy/loss:0.9472727179527283/0.1778537780046463\n",
      "[validation]accuracy/loss:0.9473913311958313/0.18061195313930511\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[validation]accuracy/loss:0.9474999904632568/0.17810410261154175\n",
      "[validation]accuracy/loss:0.9483999609947205/0.17516782879829407\n",
      "[validation]accuracy/loss:0.9496153593063354/0.1706186681985855\n",
      "[validation]accuracy/loss:0.9507406949996948/0.16742965579032898\n",
      "[validation]accuracy/loss:0.9499999284744263/0.1684337556362152\n",
      "[validation]accuracy/loss:0.9489654898643494/0.17309990525245667\n",
      "[validation]accuracy/loss:0.947666585445404/0.18104137480258942\n",
      "[validation]accuracy/loss:0.9480644464492798/0.17808343470096588\n",
      "[validation]accuracy/loss:0.948437511920929/0.17772985994815826\n",
      "[validation]accuracy/loss:0.9487878680229187/0.1772851049900055\n",
      "[validation]accuracy/loss:0.9497058987617493/0.1740136742591858\n",
      "[validation]accuracy/loss:0.9505714178085327/0.17100749909877777\n",
      "[validation]accuracy/loss:0.9502777457237244/0.17110168933868408\n",
      "[validation]accuracy/loss:0.9502702951431274/0.17160700261592865\n",
      "[validation]accuracy/loss:0.9507895112037659/0.16980819404125214\n",
      "[validation]accuracy/loss:0.9502564668655396/0.17090335488319397\n",
      "[validation]accuracy/loss:0.9494999647140503/0.17357489466667175\n",
      "[validation]accuracy/loss:0.9482927322387695/0.1769236922264099\n",
      "[validation]accuracy/loss:0.9490476250648499/0.17539331316947937\n",
      "[validation]accuracy/loss:0.9493023157119751/0.17410948872566223\n",
      "[validation]accuracy/loss:0.9497727751731873/0.17287354171276093\n",
      "[validation]accuracy/loss:0.9504444599151611/0.17064213752746582\n",
      "[validation]accuracy/loss:0.9504348039627075/0.17023682594299316\n",
      "[validation]accuracy/loss:0.9506382942199707/0.16853855550289154\n",
      "[validation]accuracy/loss:0.9512500762939453/0.16732844710350037\n",
      "[validation]accuracy/loss:0.9512245655059814/0.16747473180294037\n",
      "[validation]accuracy/loss:0.9504001140594482/0.16867156326770782\n",
      "[validation]accuracy/loss:0.9505882859230042/0.1685788333415985\n",
      "[validation]accuracy/loss:0.950769305229187/0.16734661161899567\n",
      "[validation]accuracy/loss:0.9507547616958618/0.1667412519454956\n",
      "[validation]accuracy/loss:0.9509259462356567/0.1666666567325592\n",
      "[validation]accuracy/loss:0.9509091377258301/0.16615547239780426\n",
      "[validation]accuracy/loss:0.9512499570846558/0.1661454290151596\n",
      "[validation]accuracy/loss:0.9514034390449524/0.16500458121299744\n",
      "[validation]accuracy/loss:0.9512068033218384/0.16602221131324768\n",
      "[validation]accuracy/loss:0.9513558149337769/0.16540467739105225\n",
      "[validation]accuracy/loss:0.951833188533783/0.16352398693561554\n",
      "[validation]accuracy/loss:0.9518031477928162/0.16257016360759735\n",
      "[validation]accuracy/loss:0.9525805711746216/0.16075953841209412\n",
      "[validation]accuracy/loss:0.9519046545028687/0.16168352961540222\n",
      "[validation]accuracy/loss:0.952343761920929/0.1607695370912552\n",
      "[validation]accuracy/loss:0.9520000219345093/0.1616724133491516\n",
      "[validation]accuracy/loss:0.9524242281913757/0.16040156781673431\n",
      "[validation]accuracy/loss:0.9522387981414795/0.16043755412101746\n",
      "[validation]accuracy/loss:0.9524999260902405/0.15926983952522278\n",
      "[validation]accuracy/loss:0.9527536034584045/0.15867562592029572\n",
      "[validation]accuracy/loss:0.9531428813934326/0.15740495920181274\n",
      "[validation]accuracy/loss:0.9530985951423645/0.1579514890909195\n",
      "[validation]accuracy/loss:0.95333331823349/0.15703530609607697\n",
      "[validation]accuracy/loss:0.9535616636276245/0.1565435379743576\n",
      "[validation]accuracy/loss:0.9532432556152344/0.15673254430294037\n",
      "[validation]accuracy/loss:0.95333331823349/0.15608970820903778\n",
      "[validation]accuracy/loss:0.9534210562705994/0.1559489369392395\n",
      "[validation]accuracy/loss:0.9532467722892761/0.15634000301361084\n",
      "[validation]accuracy/loss:0.9528204798698425/0.1582128256559372\n",
      "[validation]accuracy/loss:0.9531645774841309/0.15704046189785004\n",
      "[validation]accuracy/loss:0.953499972820282/0.15598948299884796\n",
      "[validation]accuracy/loss:0.9534567594528198/0.15549132227897644\n",
      "[validation]accuracy/loss:0.9539023637771606/0.15406352281570435\n",
      "[validation]accuracy/loss:0.9543372392654419/0.15268315374851227\n",
      "[validation]accuracy/loss:0.9548808336257935/0.15137827396392822\n",
      "[validation]accuracy/loss:0.9551764130592346/0.1503884643316269\n",
      "[validation]accuracy/loss:0.9555813074111938/0.14913535118103027\n",
      "[validation]accuracy/loss:0.9557470679283142/0.14851051568984985\n",
      "[validation]accuracy/loss:0.9559091329574585/0.14750979840755463\n",
      "[validation]accuracy/loss:0.9558426737785339/0.1477728635072708\n",
      "[validation]accuracy/loss:0.956333339214325/0.14635126292705536\n",
      "[validation]accuracy/loss:0.956703245639801/0.14503630995750427\n",
      "[validation]accuracy/loss:0.9568477869033813/0.14396773278713226\n",
      "[validation]accuracy/loss:0.9569892287254333/0.143831267952919\n",
      "[validation]accuracy/loss:0.9564893841743469/0.1452835351228714\n",
      "[validation]accuracy/loss:0.9563158750534058/0.145429328083992\n",
      "[validation]accuracy/loss:0.9567707180976868/0.14414890110492706\n",
      "[validation]accuracy/loss:0.9568040370941162/0.14370682835578918\n",
      "[validation]accuracy/loss:0.9564284682273865/0.14683660864830017\n",
      "[validation]accuracy/loss:0.956868588924408/0.14552488923072815\n",
      "[validation]accuracy/loss:0.9569998979568481/0.14695875346660614\n",
      "epoch:2,batch:0,loss is:[0.215702]\n",
      "epoch:2,batch:200,loss is:[0.06034094]\n",
      "epoch:2,batch:400,loss is:[0.19594282]\n",
      "[validation]accuracy/loss:0.9800000190734863/0.07650522142648697\n",
      "[validation]accuracy/loss:0.9750000238418579/0.07749447226524353\n",
      "[validation]accuracy/loss:0.9666666984558105/0.1312781274318695\n",
      "[validation]accuracy/loss:0.95250004529953/0.15346424281597137\n",
      "[validation]accuracy/loss:0.9440000653266907/0.16743242740631104\n",
      "[validation]accuracy/loss:0.9449999928474426/0.17701348662376404\n",
      "[validation]accuracy/loss:0.9457142949104309/0.17524319887161255\n",
      "[validation]accuracy/loss:0.9487500190734863/0.16840852797031403\n",
      "[validation]accuracy/loss:0.9500000476837158/0.15956106781959534\n",
      "[validation]accuracy/loss:0.9520000219345093/0.149935781955719\n",
      "[validation]accuracy/loss:0.9545454382896423/0.14238464832305908\n",
      "[validation]accuracy/loss:0.9566666483879089/0.13772763311862946\n",
      "[validation]accuracy/loss:0.9546153545379639/0.1463521420955658\n",
      "[validation]accuracy/loss:0.9557142853736877/0.14363841712474823\n",
      "[validation]accuracy/loss:0.956000030040741/0.1408514827489853\n",
      "[validation]accuracy/loss:0.9562500715255737/0.13761988282203674\n",
      "[validation]accuracy/loss:0.957058846950531/0.13478226959705353\n",
      "[validation]accuracy/loss:0.9572222232818604/0.13618618249893188\n",
      "[validation]accuracy/loss:0.9578946828842163/0.13263651728630066\n",
      "[validation]accuracy/loss:0.9579998850822449/0.13590648770332336\n",
      "[validation]accuracy/loss:0.9571427702903748/0.13953913748264313\n",
      "[validation]accuracy/loss:0.956818163394928/0.14206154644489288\n",
      "[validation]accuracy/loss:0.95652174949646/0.14482960104942322\n",
      "[validation]accuracy/loss:0.9566666483879089/0.1417965441942215\n",
      "[validation]accuracy/loss:0.9567999243736267/0.14044110476970673\n",
      "[validation]accuracy/loss:0.9580768346786499/0.13669510185718536\n",
      "[validation]accuracy/loss:0.9585184454917908/0.1344352662563324\n",
      "[validation]accuracy/loss:0.9582142233848572/0.13361512124538422\n",
      "[validation]accuracy/loss:0.9575861692428589/0.1371791958808899\n",
      "[validation]accuracy/loss:0.9563332796096802/0.1437702178955078\n",
      "[validation]accuracy/loss:0.9570966958999634/0.14108620584011078\n",
      "[validation]accuracy/loss:0.9571875333786011/0.14093488454818726\n",
      "[validation]accuracy/loss:0.957575798034668/0.1412564218044281\n",
      "[validation]accuracy/loss:0.9582353234291077/0.13887226581573486\n",
      "[validation]accuracy/loss:0.9591429829597473/0.13622617721557617\n",
      "[validation]accuracy/loss:0.9591667652130127/0.13610178232192993\n",
      "[validation]accuracy/loss:0.9589189887046814/0.13686531782150269\n",
      "[validation]accuracy/loss:0.9592106342315674/0.13512752950191498\n",
      "[validation]accuracy/loss:0.9587180018424988/0.13730116188526154\n",
      "[validation]accuracy/loss:0.9582500457763672/0.13884799182415009\n",
      "[validation]accuracy/loss:0.957317054271698/0.14135301113128662\n",
      "[validation]accuracy/loss:0.9578571319580078/0.14074955880641937\n",
      "[validation]accuracy/loss:0.9583720564842224/0.13919711112976074\n",
      "[validation]accuracy/loss:0.9586363434791565/0.13781562447547913\n",
      "[validation]accuracy/loss:0.9591110944747925/0.13629136979579926\n",
      "[validation]accuracy/loss:0.9591304063796997/0.13597585260868073\n",
      "[validation]accuracy/loss:0.959361732006073/0.13436633348464966\n",
      "[validation]accuracy/loss:0.9595833420753479/0.13315822184085846\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[validation]accuracy/loss:0.9593877792358398/0.13318386673927307\n",
      "[validation]accuracy/loss:0.9592000842094421/0.13428479433059692\n",
      "[validation]accuracy/loss:0.9592157006263733/0.13449056446552277\n",
      "[validation]accuracy/loss:0.9596154093742371/0.13323958218097687\n",
      "[validation]accuracy/loss:0.9594340324401855/0.1324617713689804\n",
      "[validation]accuracy/loss:0.9594444632530212/0.13262946903705597\n",
      "[validation]accuracy/loss:0.9590908885002136/0.13234843313694\n",
      "[validation]accuracy/loss:0.9592857360839844/0.13228856027126312\n",
      "[validation]accuracy/loss:0.959473729133606/0.131154403090477\n",
      "[validation]accuracy/loss:0.9593104124069214/0.1319688856601715\n",
      "[validation]accuracy/loss:0.9593220949172974/0.13144724071025848\n",
      "[validation]accuracy/loss:0.9598333835601807/0.12988881766796112\n",
      "[validation]accuracy/loss:0.9600000977516174/0.12928226590156555\n",
      "[validation]accuracy/loss:0.960483968257904/0.12781524658203125\n",
      "[validation]accuracy/loss:0.9601588249206543/0.12885400652885437\n",
      "[validation]accuracy/loss:0.9603124856948853/0.12835624814033508\n",
      "[validation]accuracy/loss:0.9601538181304932/0.1287350356578827\n",
      "[validation]accuracy/loss:0.9603030681610107/0.12807440757751465\n",
      "[validation]accuracy/loss:0.9602985382080078/0.1275991052389145\n",
      "[validation]accuracy/loss:0.9604412317276001/0.1267482191324234\n",
      "[validation]accuracy/loss:0.9605798125267029/0.12648874521255493\n",
      "[validation]accuracy/loss:0.9610000848770142/0.12544067203998566\n",
      "[validation]accuracy/loss:0.9608451128005981/0.1258058398962021\n",
      "[validation]accuracy/loss:0.960972249507904/0.12501446902751923\n",
      "[validation]accuracy/loss:0.9609588980674744/0.12506993114948273\n",
      "[validation]accuracy/loss:0.9604054093360901/0.12558063864707947\n",
      "[validation]accuracy/loss:0.9605333209037781/0.1252010613679886\n",
      "[validation]accuracy/loss:0.9606578946113586/0.1249442994594574\n",
      "[validation]accuracy/loss:0.9605194926261902/0.125325545668602\n",
      "[validation]accuracy/loss:0.9599999785423279/0.127433642745018\n",
      "[validation]accuracy/loss:0.9602531790733337/0.1266322284936905\n",
      "[validation]accuracy/loss:0.9604999423027039/0.12580184638500214\n",
      "[validation]accuracy/loss:0.9604937434196472/0.12571577727794647\n",
      "[validation]accuracy/loss:0.9608535766601562/0.12453494966030121\n",
      "[validation]accuracy/loss:0.9612047076225281/0.12345369160175323\n",
      "[validation]accuracy/loss:0.9616665840148926/0.12244075536727905\n",
      "[validation]accuracy/loss:0.9619998931884766/0.12150860577821732\n",
      "[validation]accuracy/loss:0.9624417424201965/0.12045744061470032\n",
      "[validation]accuracy/loss:0.962528645992279/0.12003850191831589\n",
      "[validation]accuracy/loss:0.9627273082733154/0.11920533329248428\n",
      "[validation]accuracy/loss:0.9625842571258545/0.11911323666572571\n",
      "[validation]accuracy/loss:0.9629999995231628/0.11793491989374161\n",
      "[validation]accuracy/loss:0.9634065628051758/0.11679457873106003\n",
      "[validation]accuracy/loss:0.9635869860649109/0.11602658778429031\n",
      "[validation]accuracy/loss:0.963655948638916/0.1160411387681961\n",
      "[validation]accuracy/loss:0.9632979035377502/0.11695187538862228\n",
      "[validation]accuracy/loss:0.9632631540298462/0.11688313633203506\n",
      "[validation]accuracy/loss:0.963645875453949/0.11584790796041489\n",
      "[validation]accuracy/loss:0.9637113809585571/0.1155204102396965\n",
      "[validation]accuracy/loss:0.9633674025535583/0.1183745488524437\n",
      "[validation]accuracy/loss:0.963737428188324/0.11730943620204926\n",
      "[validation]accuracy/loss:0.9637000560760498/0.11873506754636765\n",
      "epoch:3,batch:0,loss is:[0.06662053]\n",
      "epoch:3,batch:200,loss is:[0.16230756]\n",
      "epoch:3,batch:400,loss is:[0.13213824]\n",
      "[validation]accuracy/loss:0.9700000286102295/0.06447252631187439\n",
      "[validation]accuracy/loss:0.9800000190734863/0.06368453800678253\n",
      "[validation]accuracy/loss:0.9700000286102295/0.10982528328895569\n",
      "[validation]accuracy/loss:0.9650000333786011/0.12671129405498505\n",
      "[validation]accuracy/loss:0.9600000381469727/0.13820675015449524\n",
      "[validation]accuracy/loss:0.9583333134651184/0.14706583321094513\n",
      "[validation]accuracy/loss:0.9600000381469727/0.14320699870586395\n",
      "[validation]accuracy/loss:0.9625000357627869/0.1370818167924881\n",
      "[validation]accuracy/loss:0.9622222185134888/0.13123735785484314\n",
      "[validation]accuracy/loss:0.9629999995231628/0.12579044699668884\n",
      "[validation]accuracy/loss:0.9663636684417725/0.11855019629001617\n",
      "[validation]accuracy/loss:0.9675000309944153/0.1140240952372551\n",
      "[validation]accuracy/loss:0.9646154642105103/0.12398552894592285\n",
      "[validation]accuracy/loss:0.9642857909202576/0.1230047419667244\n",
      "[validation]accuracy/loss:0.9653334021568298/0.12097068130970001\n",
      "[validation]accuracy/loss:0.9650000333786011/0.11765315383672714\n",
      "[validation]accuracy/loss:0.9658823609352112/0.11643178015947342\n",
      "[validation]accuracy/loss:0.9666666388511658/0.11697165668010712\n",
      "[validation]accuracy/loss:0.966315746307373/0.11432202905416489\n",
      "[validation]accuracy/loss:0.9659999012947083/0.11698314547538757\n",
      "[validation]accuracy/loss:0.9652380347251892/0.12046517431735992\n",
      "[validation]accuracy/loss:0.964090883731842/0.12464499473571777\n",
      "[validation]accuracy/loss:0.9639129638671875/0.12736201286315918\n",
      "[validation]accuracy/loss:0.9649999737739563/0.12412852048873901\n",
      "[validation]accuracy/loss:0.9647999405860901/0.12333660572767258\n",
      "[validation]accuracy/loss:0.9653845429420471/0.12045808881521225\n",
      "[validation]accuracy/loss:0.9659258723258972/0.1180548295378685\n",
      "[validation]accuracy/loss:0.965714156627655/0.11810418218374252\n",
      "[validation]accuracy/loss:0.964137852191925/0.12271531671285629\n",
      "[validation]accuracy/loss:0.9629999399185181/0.12906219065189362\n",
      "[validation]accuracy/loss:0.9635483026504517/0.12658613920211792\n",
      "[validation]accuracy/loss:0.9643750190734863/0.12552092969417572\n",
      "[validation]accuracy/loss:0.9642423987388611/0.12596802413463593\n",
      "[validation]accuracy/loss:0.9647058844566345/0.12358716130256653\n",
      "[validation]accuracy/loss:0.9657142758369446/0.12125217169523239\n",
      "[validation]accuracy/loss:0.9655554890632629/0.12065675854682922\n",
      "[validation]accuracy/loss:0.9651350975036621/0.12169240415096283\n",
      "[validation]accuracy/loss:0.9652631878852844/0.120101198554039\n",
      "[validation]accuracy/loss:0.9648718237876892/0.1213432252407074\n",
      "[validation]accuracy/loss:0.9645000696182251/0.12307963520288467\n",
      "[validation]accuracy/loss:0.963902473449707/0.12429546564817429\n",
      "[validation]accuracy/loss:0.9642857313156128/0.12347909063100815\n",
      "[validation]accuracy/loss:0.9646511673927307/0.12247998267412186\n",
      "[validation]accuracy/loss:0.9647727608680725/0.12134715914726257\n",
      "[validation]accuracy/loss:0.9651111364364624/0.11977668106555939\n",
      "[validation]accuracy/loss:0.9647826552391052/0.11944051831960678\n",
      "[validation]accuracy/loss:0.9651063680648804/0.11796880513429642\n",
      "[validation]accuracy/loss:0.9649999737739563/0.11684887856245041\n",
      "[validation]accuracy/loss:0.9648979306221008/0.11721332371234894\n",
      "[validation]accuracy/loss:0.9647999405860901/0.11770410090684891\n",
      "[validation]accuracy/loss:0.9647058248519897/0.11752958595752716\n",
      "[validation]accuracy/loss:0.9649999141693115/0.1161220371723175\n",
      "[validation]accuracy/loss:0.9649055600166321/0.11582992970943451\n",
      "[validation]accuracy/loss:0.9651851058006287/0.11610496044158936\n",
      "[validation]accuracy/loss:0.9654544591903687/0.11561501026153564\n",
      "[validation]accuracy/loss:0.9655357003211975/0.11500787734985352\n",
      "[validation]accuracy/loss:0.9659649133682251/0.1137889102101326\n",
      "[validation]accuracy/loss:0.9656897187232971/0.11457881331443787\n",
      "[validation]accuracy/loss:0.9655932188034058/0.11445394903421402\n",
      "[validation]accuracy/loss:0.9660000205039978/0.11314448714256287\n",
      "[validation]accuracy/loss:0.9660656452178955/0.1124342530965805\n",
      "[validation]accuracy/loss:0.9666129946708679/0.11114438623189926\n",
      "[validation]accuracy/loss:0.9663493037223816/0.11177170276641846\n",
      "[validation]accuracy/loss:0.9664062857627869/0.11128776520490646\n",
      "[validation]accuracy/loss:0.9660000205039978/0.11230333894491196\n",
      "[validation]accuracy/loss:0.9660606384277344/0.11191900074481964\n",
      "[validation]accuracy/loss:0.9661194682121277/0.11172199994325638\n",
      "[validation]accuracy/loss:0.9661765098571777/0.11116126924753189\n",
      "[validation]accuracy/loss:0.9662319421768188/0.11103394627571106\n",
      "[validation]accuracy/loss:0.9665715098381042/0.110063835978508\n",
      "[validation]accuracy/loss:0.9667606353759766/0.11035709828138351\n",
      "[validation]accuracy/loss:0.9670833945274353/0.10952338576316833\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[validation]accuracy/loss:0.966986358165741/0.10938530415296555\n",
      "[validation]accuracy/loss:0.9666216969490051/0.10944417119026184\n",
      "[validation]accuracy/loss:0.9668001532554626/0.10907867550849915\n",
      "[validation]accuracy/loss:0.9668422341346741/0.10892068594694138\n",
      "[validation]accuracy/loss:0.9666234850883484/0.10951230674982071\n",
      "[validation]accuracy/loss:0.966025710105896/0.1115577220916748\n",
      "[validation]accuracy/loss:0.9660760164260864/0.11072889715433121\n",
      "[validation]accuracy/loss:0.9664999842643738/0.10981501638889313\n",
      "[validation]accuracy/loss:0.9664197564125061/0.1096237376332283\n",
      "[validation]accuracy/loss:0.9667072892189026/0.10871340334415436\n",
      "[validation]accuracy/loss:0.9669879078865051/0.10762812942266464\n",
      "[validation]accuracy/loss:0.967261791229248/0.10670981556177139\n",
      "[validation]accuracy/loss:0.967529296875/0.10590869933366776\n",
      "[validation]accuracy/loss:0.9677905440330505/0.10504323244094849\n",
      "[validation]accuracy/loss:0.9679309129714966/0.10464147478342056\n",
      "[validation]accuracy/loss:0.9680681824684143/0.10387841612100601\n",
      "[validation]accuracy/loss:0.9678651690483093/0.10398678481578827\n",
      "[validation]accuracy/loss:0.9682222008705139/0.10291604697704315\n",
      "[validation]accuracy/loss:0.9685714244842529/0.1019086241722107\n",
      "[validation]accuracy/loss:0.9688042998313904/0.10100268572568893\n",
      "[validation]accuracy/loss:0.9689247608184814/0.10109980404376984\n",
      "[validation]accuracy/loss:0.968510627746582/0.10227897763252258\n",
      "[validation]accuracy/loss:0.9687368273735046/0.10209181904792786\n",
      "[validation]accuracy/loss:0.9690625071525574/0.10114189237356186\n",
      "[validation]accuracy/loss:0.969072163105011/0.10104887187480927\n",
      "[validation]accuracy/loss:0.9686734676361084/0.10420306026935577\n",
      "[validation]accuracy/loss:0.968989908695221/0.10326287895441055\n",
      "[validation]accuracy/loss:0.9688999652862549/0.10499797016382217\n",
      "epoch:4,batch:0,loss is:[0.08983368]\n",
      "epoch:4,batch:200,loss is:[0.21750121]\n",
      "epoch:4,batch:400,loss is:[0.04428688]\n",
      "[validation]accuracy/loss:0.9800000190734863/0.04784338176250458\n",
      "[validation]accuracy/loss:0.9850000143051147/0.0522414967417717\n",
      "[validation]accuracy/loss:0.9766666889190674/0.09973801672458649\n",
      "[validation]accuracy/loss:0.9625000357627869/0.12336056679487228\n",
      "[validation]accuracy/loss:0.9600000381469727/0.13365820050239563\n",
      "[validation]accuracy/loss:0.9583333134651184/0.14483043551445007\n",
      "[validation]accuracy/loss:0.9600000381469727/0.14179155230522156\n",
      "[validation]accuracy/loss:0.9612500071525574/0.13487114012241364\n",
      "[validation]accuracy/loss:0.9633333683013916/0.12783212959766388\n",
      "[validation]accuracy/loss:0.965999960899353/0.11891111731529236\n",
      "[validation]accuracy/loss:0.9681817889213562/0.11204053461551666\n",
      "[validation]accuracy/loss:0.9699999690055847/0.10544251650571823\n",
      "[validation]accuracy/loss:0.9676922559738159/0.11355029791593552\n",
      "[validation]accuracy/loss:0.9678570628166199/0.11007940024137497\n",
      "[validation]accuracy/loss:0.9686666131019592/0.10603372007608414\n",
      "[validation]accuracy/loss:0.9681249856948853/0.104247085750103\n",
      "[validation]accuracy/loss:0.9688234925270081/0.10330550372600555\n",
      "[validation]accuracy/loss:0.9683332443237305/0.10478383302688599\n",
      "[validation]accuracy/loss:0.9689472317695618/0.10201776027679443\n",
      "[validation]accuracy/loss:0.9679999351501465/0.10405294597148895\n",
      "[validation]accuracy/loss:0.9671428203582764/0.10540604591369629\n",
      "[validation]accuracy/loss:0.9659090638160706/0.1089971512556076\n",
      "[validation]accuracy/loss:0.9652174115180969/0.11223582178354263\n",
      "[validation]accuracy/loss:0.9662500023841858/0.10949818789958954\n",
      "[validation]accuracy/loss:0.9663999676704407/0.10883044451475143\n",
      "[validation]accuracy/loss:0.9673076868057251/0.10615307092666626\n",
      "[validation]accuracy/loss:0.9677777290344238/0.10408901423215866\n",
      "[validation]accuracy/loss:0.9678570628166199/0.10350914299488068\n",
      "[validation]accuracy/loss:0.966551661491394/0.10746216028928757\n",
      "[validation]accuracy/loss:0.9653332829475403/0.11372847855091095\n",
      "[validation]accuracy/loss:0.9654838442802429/0.1124761551618576\n",
      "[validation]accuracy/loss:0.9659374952316284/0.11193698644638062\n",
      "[validation]accuracy/loss:0.9660605788230896/0.11263860762119293\n",
      "[validation]accuracy/loss:0.9664705991744995/0.1107373833656311\n",
      "[validation]accuracy/loss:0.9671429395675659/0.10851914435625076\n",
      "[validation]accuracy/loss:0.9672223329544067/0.10841947793960571\n",
      "[validation]accuracy/loss:0.9667568802833557/0.10961946845054626\n",
      "[validation]accuracy/loss:0.9671053886413574/0.10797175019979477\n",
      "[validation]accuracy/loss:0.9661539793014526/0.11018673330545425\n",
      "[validation]accuracy/loss:0.965999960899353/0.1114296093583107\n",
      "[validation]accuracy/loss:0.9658536314964294/0.11143262684345245\n",
      "[validation]accuracy/loss:0.9661904573440552/0.11035259068012238\n",
      "[validation]accuracy/loss:0.9665115475654602/0.10939791053533554\n",
      "[validation]accuracy/loss:0.9670454263687134/0.10792496055364609\n",
      "[validation]accuracy/loss:0.9677777886390686/0.10640119016170502\n",
      "[validation]accuracy/loss:0.9680434465408325/0.10559798777103424\n",
      "[validation]accuracy/loss:0.968510627746582/0.10428344458341599\n",
      "[validation]accuracy/loss:0.9685416221618652/0.10355748236179352\n",
      "[validation]accuracy/loss:0.968163251876831/0.10402607917785645\n",
      "[validation]accuracy/loss:0.9681999683380127/0.10439597070217133\n",
      "[validation]accuracy/loss:0.9680392146110535/0.10440728813409805\n",
      "[validation]accuracy/loss:0.9682692289352417/0.10350465029478073\n",
      "[validation]accuracy/loss:0.9683018922805786/0.10334193706512451\n",
      "[validation]accuracy/loss:0.96833336353302/0.10373973846435547\n",
      "[validation]accuracy/loss:0.9683637022972107/0.10327059775590897\n",
      "[validation]accuracy/loss:0.9683929085731506/0.103025883436203\n",
      "[validation]accuracy/loss:0.9689474105834961/0.101981021463871\n",
      "[validation]accuracy/loss:0.968620777130127/0.10263549536466599\n",
      "[validation]accuracy/loss:0.9686441421508789/0.1021074503660202\n",
      "[validation]accuracy/loss:0.9691667556762695/0.10092132538557053\n",
      "[validation]accuracy/loss:0.9691804647445679/0.10052508115768433\n",
      "[validation]accuracy/loss:0.9695162773132324/0.09931673854589462\n",
      "[validation]accuracy/loss:0.9692065119743347/0.09997056424617767\n",
      "[validation]accuracy/loss:0.9692187309265137/0.09958576411008835\n",
      "[validation]accuracy/loss:0.9689230918884277/0.1002696081995964\n",
      "[validation]accuracy/loss:0.9689394235610962/0.10010191053152084\n",
      "[validation]accuracy/loss:0.9689552187919617/0.09979705512523651\n",
      "[validation]accuracy/loss:0.9689705967903137/0.09934256225824356\n",
      "[validation]accuracy/loss:0.9689854979515076/0.0992807075381279\n",
      "[validation]accuracy/loss:0.9692856669425964/0.09832106530666351\n",
      "[validation]accuracy/loss:0.9694366455078125/0.09825149178504944\n",
      "[validation]accuracy/loss:0.9697222113609314/0.09743551164865494\n",
      "[validation]accuracy/loss:0.969726026058197/0.09738371521234512\n",
      "[validation]accuracy/loss:0.9694594144821167/0.09770920127630234\n",
      "[validation]accuracy/loss:0.9696000218391418/0.09747599065303802\n",
      "[validation]accuracy/loss:0.9698684215545654/0.096936896443367\n",
      "[validation]accuracy/loss:0.9697402119636536/0.0972861722111702\n",
      "[validation]accuracy/loss:0.9693589806556702/0.09883557260036469\n",
      "[validation]accuracy/loss:0.9694937467575073/0.0983198806643486\n",
      "[validation]accuracy/loss:0.9698749780654907/0.09747762978076935\n",
      "[validation]accuracy/loss:0.9698765277862549/0.09730181097984314\n",
      "[validation]accuracy/loss:0.9701219201087952/0.09649118781089783\n",
      "[validation]accuracy/loss:0.9704818725585938/0.09545306861400604\n",
      "[validation]accuracy/loss:0.9708333015441895/0.0945364460349083\n",
      "[validation]accuracy/loss:0.97105872631073/0.09381083399057388\n",
      "[validation]accuracy/loss:0.971278965473175/0.09314977377653122\n",
      "[validation]accuracy/loss:0.9713792204856873/0.0928163006901741\n",
      "[validation]accuracy/loss:0.9717044830322266/0.0920136347413063\n",
      "[validation]accuracy/loss:0.9714605808258057/0.0924389511346817\n",
      "[validation]accuracy/loss:0.9717776775360107/0.09155670553445816\n",
      "[validation]accuracy/loss:0.9720878005027771/0.09066762030124664\n",
      "[validation]accuracy/loss:0.9722824692726135/0.08996938914060593\n",
      "[validation]accuracy/loss:0.9722579717636108/0.09020563215017319\n",
      "[validation]accuracy/loss:0.9719148278236389/0.09125713258981705\n",
      "[validation]accuracy/loss:0.9721051454544067/0.09095458686351776\n",
      "[validation]accuracy/loss:0.9723957180976868/0.09011118859052658\n",
      "[validation]accuracy/loss:0.9723710417747498/0.08976161479949951\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[validation]accuracy/loss:0.9719386696815491/0.09332488477230072\n",
      "[validation]accuracy/loss:0.9722221493721008/0.09249075502157211\n",
      "[validation]accuracy/loss:0.9721999168395996/0.09403007477521896\n"
     ]
    }
   ],
   "source": [
    "train_loader=load_data('train')\n",
    "valid_loader=load_data('valid')\n",
    "model=LeNetModel()\n",
    "train(model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "paddle.save(model.state_dict(),'mnist-cnn.pdparams')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "from PIL import Image\n",
    "import numpy as np\n",
    "im=Image.open('0.jpg').convert('L')\n",
    "im=im.resize((28,28),Image.ANTIALIAS)\n",
    "img=np.array(im).reshape(1,1,28,28).astype('float32')\n",
    "img=1.0-img/255"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "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\n",
      "text/plain": [
       "<Figure size 144x144 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.figure(figsize=(2,2))\n",
    "plt.imshow(im,cmap=plt.cm.binary)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "本次预测的数字是: 0\n"
     ]
    }
   ],
   "source": [
    "model=LeNetModel()\n",
    "params_file_path='mnist-cnn.pdparams'\n",
    "param_dict=paddle.load(params_file_path)\n",
    "model.load_dict(param_dict)\n",
    "model.eval()\n",
    "tensor_img=img\n",
    "results=model(paddle.to_tensor(tensor_img))\n",
    "lab=np.argsort(results.numpy())\n",
    "print(\"本次预测的数字是:\",lab[0][-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
